package cn.edu.nchu.controller;

import cn.edu.nchu.entity.CommonResult;
import cn.edu.nchu.entity.TestInfo;
import cn.edu.nchu.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/search/{id}")
    public CommonResult search(@PathVariable("id") Integer id){
        TestInfo result = testService.findById(id);
        if (result != null) {
            return new CommonResult(200, "查询成功！", result);
        }
        return new CommonResult(300, "查询失败！", result);
    }

    @PostMapping("/create")
    public CommonResult create(@RequestBody TestInfo testInfo){
        TestInfo result = testService.create(testInfo);
        if (result != null) {
            return new CommonResult(200, "添加成功！", result);
        }
        return new CommonResult(300, "添加失败！", result);
    }
}
